package com.voxel.sense.infomsg.module.trace.details;

import android.view.View;
import android.widget.TextView;

import com.example.com.common.utils.TimeUtils;
import com.example.com.common.view.recycler.RecyclerAdapter;
import com.voxel.sense.infomsg.R;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;

import butterknife.BindView;
import cyy.example.com.facotry.model.api.response.ClockInsDetailsEntity;

/**
 * Created by ChenYiYao on 2018/10/19.
 * des :
 */
public class CheckInsTimeListAdapter extends RecyclerAdapter {
    @Override
    protected int getItemViewType(int position, Object o) {
        int layoutId;
        if (o instanceof String[]) {
            layoutId = R.layout.item_recycler_checkins_det_count;
        } else {
            layoutId = R.layout.item_recycler_info_textview;
        }
        return layoutId;
    }

    @Override
    protected ViewHolder onCreateViewHolder(View root, int viewType) {
        if (viewType == R.layout.item_recycler_checkins_det_count) {
            return new CountViewhHolder(root);
        } else {
            return new ViewhHolder(root);
        }
    }


    public static class CountViewhHolder extends ViewHolder<String[]> {
        @BindView(R.id.tv_count_des) //描述
                TextView tv_count_des;
        @BindView(R.id.tv_count) //次数
                TextView tv_count;

        public CountViewhHolder(View itemView) {
            super(itemView);
        }

        @Override
        protected void onBind(String[] strings) {
            if (strings.length >= 2) {
                tv_count_des.setText(strings[0]);
                tv_count.setText(strings[1]);
            }
        }
    }

    public static class ViewhHolder extends ViewHolder {
        @BindView(R.id.tv_name)
        TextView tv_name;

        public ViewhHolder(View itemView) {
            super(itemView);
        }

        @Override
        protected void onBind(Object data) {

            if (data != null && data instanceof ClockInsDetailsEntity.CoordinateListBean.ValuesBean) {
                ClockInsDetailsEntity.CoordinateListBean.ValuesBean bean = (ClockInsDetailsEntity.CoordinateListBean.ValuesBean) data;
                DateFormat DEFAULT_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
//                TimeUtils.string2Millis(bean.getTime())
                String s = TimeUtils.millis2String(TimeUtils.string2Millis(bean.getTime()),
                        new SimpleDateFormat("HH:mm:ss", Locale.getDefault()));
                tv_name.setText(s);
            } else if (data != null && data instanceof ClockInsDetailsEntity.CoordinateListBean) {
                tv_name.setText(((ClockInsDetailsEntity.CoordinateListBean) data).getTime());
            }
        }
    }

}
